The present invention relates to computer-implemented methods for modifying an electronic image.
Computer painting programs allow the user to manipulate an electronic image with an onscreen xe2x80x9cbrushxe2x80x9d controlled by an input device such as a mouse. The user may typically select from among a variety of brush shapes, e.g., circle, square, or single pixel. The user drags the brush along a xe2x80x9ctrajectoryxe2x80x9d from one location to another within the image, thereby defining an xe2x80x9cenvelope.xe2x80x9d Pixels within the envelope are affected by the operation of the brush. One type of brush allows a user to xe2x80x9cpaintxe2x80x9d colors and textures into the envelope. The paint brush replaces the pixels in the envelope with the image of the brush.
Often it is desirable to extract an object from its background in an electronic image, referred to herein as a xe2x80x9csource image.xe2x80x9d The object can then be placed in another image, referred to herein as a xe2x80x9cdestination image.xe2x80x9d One computer application that can accomplish this extraction is Adobe Photoshop(trademark), which includes an object extraction tool. Object extraction tools create a mask that indicates the degree to which each pixel in the image is associated with the background or the foreground object. For an eight-bit mask, a mask value of zero for a pixel indicates that the pixel belongs only to the background; a mask value of 255 indicates that the pixel belongs only to the foreground object. Pixels having mask values between zero and 255 belong partly to both the foreground object and the background. Pixels belonging to both the foreground object and the background can occur where the edges of the object blend into the background, for example.
In addition to the mask, object extraction tools may produce altered color values for pixels belonging to both the foreground object and the background. These new colors, obtained by removing background color contamination, represent the foreground object""s intrinsic color values.
Object extraction tools work well with objects having simple edges, but encounter difficulty when faced with objects having complex edges. These difficulties result in the unwanted appearance of opaque (high mask value) pixels in regions which should be transparent (low mask values) as well as transparent pixels in regions which should be opaque. These artifacts can be fixed by touching up the resultant image with various paint brushes and erasers applied either to the image, the mask or both. However, standard brushes do not respect mask edges and consequently can require a large amount of manual effort to clean up an imperfect mask edge. Nor do they provide a simple means of shaping and sharpening edges.
In general, in one aspect, the invention features a method and computer program product for painting in an image having one or more channels. It includes selecting a portion of the image in response to user manipulation of a brush having two or more regions; increasing the value of one or more of the channels covered by one of the regions; and decreasing the value of one or more of the channels covered by another one of the regions.
In general, in one aspect, the invention features a method and computer program product for manipulating an edge in an image. It includes selecting a portion of the image in response to user manipulation of a brush having two or more regions, the portion including an edge; orienting the brush so that a first region lies on a first side of the edge and a second region lies on a second side of the edge; performing a first effect in the portion of the image covered by the first region; and performing a second effect in the portion of the image covered by the second region. The edge can be an edge of a mask.
Particular implementations can include one or more of the following features. The image includes a mask channel defining the mask, and the method includes performing the first and second effects on the mask channel. The first side of the extraction mask edge is of greater opacity than the second side of the extraction mask edge, and the method includes increasing the opacity of the mask in the first region; and decreasing the opacity of the mask in the second region. The image includes one or more color channels, and the method includes modifying the color values in one or more of the color channels. The image includes an object extracted from a source image, and the method includes replacing the values in the color channels covered by the first region of the image with a combination of values from the color channels in the image and source image.
Particular implementations can also include detecting the mask edge. Detecting can include calculating an angle between a reference line and a perpendicular to a potential edge; calculating an offset (the shortest distance) between a reference point and the potential edge; and calculating a measure of confidence that the potential edge is an edge of the image mask. Calculating an angle can include obtaining the average first-order moment of the mask. Calculating an angle can include obtaining the average value of the mask within the portion. Calculating an offset includes calculating the shortest distance between a reference point and the potential edge, and can also include obtaining the average value of the mask within the portion. Calculating a measure of confidence includes obtaining the average value of the mask within the portion.
In general, in one aspect, the invention features a method and computer program product for moving a mask edge of a mask in an image, the mask edge separating a region of greater opacity from a region of lesser opacity. It includes selecting a portion of the image in response to user manipulation of a brush having two or more regions, the portion including the mask edge; orienting the brush so that a first brush region lies in the region of greater opacity and a second brush region lies in the region of lesser opacity; increasing the opacity of the mask in the first region; and decreasing the opacity of the mask in the second region.
Particular implementations can include centering the brush in the vicinity of the mask edge; and repeating the increasing and decreasing steps, thereby moving the mask edge. The method can also include centering the brush on the mask edge; and repeating the increasing and decreasing steps, thereby smoothing the mask edge.
Advantages that can be seen in implementations of the invention include one or more of the following. Complex edges of extracted objects can be sharpened quickly and easily. Complex edges can be smoothed to produce cleaner edges; the smoothing is controllable by the user. Bumps can be removed from edges, the size of the bump determined by the size of the brush used. Edges can be adjusted by moving the edge boundary in a local area.
The details of one or more embodiments of the invention are set forth in the accompanying drawings and the description below. Other features and advantages of the invention will become apparent from the description, the drawings, and the claims.